package com.adee.java.nio;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.channels.SocketChannel;
import java.util.Scanner;

public class NioClientTest {
    public static void main(String[] args) throws IOException {
        SocketChannel ch = SocketChannel.open();
        //ch.configureBlocking(false);
        InetSocketAddress addr = new InetSocketAddress("127.0.0.1", 7000);
        // 如果SocketChannel处于非阻塞模式并且你调用了connect()方法的话，该方法会在一个链接建立之前就返回。
        // 你可以调用finishConnect()方法去判断一个链接有没有建立
        long m1 = System.currentTimeMillis();
        boolean connect = ch.connect(addr);
        if(connect) {
            System.out.println("connected");
            System.out.println(System.currentTimeMillis() - m1);
        }
        Scanner scanner = new Scanner(System.in);

    }
}
